Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allergies: Property-based tests. #735

Merged
merged 2 commits into from
Nov 8, 2018
Merged

allergies: Property-based tests. #735

merged 2 commits into from
Nov 8, 2018

Conversation

sshine
Copy link
Contributor

@sshine sshine commented Oct 9, 2018

I was adding the allergies exercise to the Ocaml track and wanted to write some property-based tests for it, since that seemed quicker.

I found Ocaml's QCheck library hard to understand, so I decided to write them in Haskell and port them to Ocaml. I don't know if they're really needed here, since the coverage for this exercise is already quite fine. But here they are.

@sshine
Copy link
Contributor Author

sshine commented Oct 9, 2018

From the failed build:

/home/travis/build/exercism/haskell/build/allergies/stub/test/Tests.hs:29:47: error:
    • No instance for (Show Allergen) arising from a use of ‘forAll’
    • In the expression: forAll allergenWithScore

Also, I'm sorry for the confusingly named allergies-1.2.0.7 branch; this is 1.2.0.6 because #734 didn't bump the version anyways.

Copy link
Member

@petertseng petertseng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No instance for (Show Allergen)

I wished I could tell you something like "then you should ensure there is one (otherwise it's not possible for this to be merged, by repository restrictions)", but it looks to me that both the example solution and the stub do this. So, did I miss something that would explain why this is happening?

I think I would like to have these, as

  1. we've needed a replacement for trinary and octal for some time.
  2. it's quite possible to agree that the example-based tests could possibly have some gaps.

I considered asking for some material in .meta/hints.md explaining the presence of these tests, but not even octal or trinary had such hints, nor does simple-linked-list. That's a little surprising. Will have to think about how this should be introduced to students.

So how about this. If the property-based tests were the last tests in their respective describe sections, then by the time students get there, hopefully they're already equipped to pass them. Currently, they're the first test and a student encountering this sort of testing for the first time might not know what's going on.

So I'd suggest one of the two following:

  • Move them to be the last tests in their respective describe
  • Add an explanation, either in test comments or in .meta/hints.md (which, upon README generation, is to be added to the README)

@sshine
Copy link
Contributor Author

sshine commented Oct 17, 2018

  1. we've needed a replacement for trinary and octal for some time.

Is this related to the all-your-base exercise?

I've moved them to be the last tests in their respective describe, and I've added comments above each property that explains what's going on.

Do you think I should add shrinking, @petertseng?

@sshine
Copy link
Contributor Author

sshine commented Oct 17, 2018

Travis CI passes for this one now.

Copy link
Member

@petertseng petertseng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think I should add shrinking

Usually to answer these questions I think about what it will look like for an implememtation that has some mistake in it.

I think it would make sense for the tests with multiple allergens. Remove any one allergen, probably.

I have a few other ideas for tests that would be useful. currently the isAllergicTo tests are testing that the implementation returns true when it should.

I think there's a lot of value gained by also checking that it returns false when it should. otherwise you might imagine that an implementation of const True would pass all the isAllergicTo tests (all right, there are existing example-based tests that would figure it out, but I am thinking it could be good to get coverage from the property-based tests too)

@sshine
Copy link
Contributor Author

sshine commented Oct 20, 2018

Indeed.

For the Ocaml tests, I did generate negative samples.

@sshine
Copy link
Contributor Author

sshine commented Oct 22, 2018

Negative properties and shrinking added.

Copy link
Member

@petertseng petertseng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope you don't mind if I inquire as to whether two of those tests are in fact testing something that another test has not already covered

exercises/allergies/test/Tests.hs Outdated Show resolved Hide resolved
exercises/allergies/test/Tests.hs Outdated Show resolved Hide resolved
QuickCheck depends on `Show` instance for `Allergies`.

Positive and negative properties are added.

Some shrinking occurs for tests with multiple allergens.
Copy link
Member

@petertseng petertseng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're ready to go here. I wonder how many submissions this exercise gets a day and therefore how many students will come into contact with this. If students get interested we might see about having more of these. Maybe putting quickcheck as one of the topics will help mark them.

@petertseng petertseng merged commit 68f1c00 into exercism:master Nov 8, 2018
@sshine
Copy link
Contributor Author

sshine commented Nov 8, 2018

It doesn't get a lot. I think there has been one since Jeremy reset the non-core queue.

Also, it gets unlocked after Difference Of Squares (the next-last core exercise) as the third icon, so it's kind of hidden away.

@sshine sshine deleted the allergies-1.2.0.7 branch March 12, 2019 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants